<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="template/template.xhtml">


        <ui:define name="title">
            <h:outputText value="#{msg['titulo']}"></h:outputText>
        </ui:define>

        <ui:define name="body">

            <f:loadBundle basename="programa" var="msg"/>

            <h:form id="formLista">

                <p:panel header="#{msg['tituloPrograma']}">
                    <p:dataTable id="datalist" value="#{programaM.items}" var="item"
                                 selectionMode="single" selection="#{programaM.selected}"
                                 paginator="true"
                                 rowKey="#{item.codigo}"
                                 rows="10"
                                 rowsPerPageTemplate="5,10,25,50,100"
                                 >

                        <p:ajax event="rowSelect"   update="btnApagar btnCriar btEditar"/>
                        <p:ajax event="rowUnselect" update="btnApagar btnCriar btEditar"/>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['codigo']}"/>
                            </f:facet>
                            <h:outputText value="#{item.codigo}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['nome']}"/>
                            </f:facet>
                            <h:outputText value="#{item.nome}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['xhtml']}"/>
                            </f:facet>
                            <h:outputText value="#{item.xhtml}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['mbean']}"/>
                            </f:facet>
                            <h:outputText value="#{item.mbean}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['titulo']}"/>
                            </f:facet>
                            <h:outputText value="#{item.titulo}" title="#{item.titulo}"/>
                        </p:column>


                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{msg['ajuda']}"/>
                            </f:facet>
                            <h:outputText value="#{item.ajuda}" title="#{item.ajuda}"/>
                        </p:column>



                        <f:facet name="footer">
                            <p:commandButton id="btnCriar" icon="ui-icon-plus"   value="#{padrao['criar']}"  
                                             oncomplete="PF('dialogManutencao').show()" update=":formManutencao :mensagem "
                                             action="#{programaM.novaInstancia}" />


                            <p:commandButton id="btEditar" icon="ui-icon-plus"   value="#{padrao['editar']}"  
                                             oncomplete="PF('dialogManutencao').show()" 
                                             update=":formManutencao :mensagem " disabled="#{programaM.selected eq null}" />

                            <p:commandButton id="btnApagar" icon="ui-icon-plus" 
                                             value="#{padrao['excluir']}"  
                                             action="#{programaM.remover}"
                                             ajax="false" disabled="#{programaM.selected eq null}" />
                        </f:facet>
                    </p:dataTable>
                </p:panel>
            </h:form>

            <p:dialog   widgetVar="dialogManutencao" modal="true" resizable="false" 
                        appendTo="@(body)" header="#{padrao['criarNovoRegistro']}" width="600px">
                <h:form id="formManutencao">
                    <p:panelGrid id="panelManutencao" columns="2" style="    border-style:none; width: 100%;" >
                        <p:outputLabel value="#{msg['codigo']}" for="codigo" />
                        <p:inputText value="#{programaM.selected.codigo}" disabled="true" id="codigo"  />

                        <p:outputLabel value="#{msg['nome']}" for="nome" />
                        <p:inputText value="#{programaM.selected.nome}" id="nome"  />

                        <p:outputLabel value="#{msg['xhtml']}" for="xhtml" />
                        <p:inputText value="#{programaM.selected.xhtml}" id="xhtml"  />


                        <p:outputLabel value="#{msg['mbean']}" for="mbean" />
                        <p:inputText value="#{programaM.selected.mbean}" id="mbean"  />

                        <p:outputLabel value="#{msg['titulo']}" for="titulo" />
                        <p:inputText value="#{programaM.selected.titulo}" id="titulo"  />


                        <p:outputLabel value="#{msg['ajuda']}" for="ajuda" />
                        <p:inputTextarea value="#{programaM.selected.ajuda}" id="ajuda"  />



                        <p:commandButton id="btnCancelar" icon="ui-icon-plus"   value="#{padrao['cancelar']}" 
                                         action="#{programaM.cancelar}" update="@form"    
                                         oncomplete="PF('dialogManutencao').hide()" />

                        <p:commandButton id="btnConfirmar" icon="ui-icon-plus"   
                                         value="#{padrao['confirmar']}" action="#{programaM.salvarAtualizar}"  
                                         oncomplete="PF('dialogManutencao').hide()" 
                                         update=":formLista :mensagem @form" />

                    </p:panelGrid>
                </h:form>
            </p:dialog>         
        </ui:define>
    </ui:composition>

</html>
